7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 if( defined( 'MEDIAWIKI' ) ) {
13 if($wgUseTeX) require_once( 'Math.php' );
20 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
21 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
22 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
23 var $mSubtitle, $mRedirect, $mStatusCode;
24 var $mLastModified, $mETag, $mCategoryLinks;
25 var $mScripts, $mLinkColours;
27 var $mSuppressQuickbar;
30 var $mContainsOldMagic, $mContainsNewMagic;
31 var $mIsArticleRelated;
33 var $mShowFeedLinks = false;
34 var $mEnableClientCache = true;
35 var $mArticleBodyOnly = false;
39 * Initialise private variables
41 function OutputPage() {
42 $this->mHeaders
= $this->mCookies
= $this->mMetatags
=
43 $this->mKeywords
= $this->mLinktags
= array();
44 $this->mHTMLtitle
= $this->mPagetitle
= $this->mBodytext
=
45 $this->mRedirect
= $this->mLastModified
=
46 $this->mSubtitle
= $this->mDebugtext
= $this->mRobotpolicy
=
47 $this->mOnloadHandler
= '';
48 $this->mIsArticleRelated
= $this->mIsarticle
= $this->mPrintable
= true;
49 $this->mSuppressQuickbar
= $this->mPrintable
= false;
50 $this->mLanguageLinks
= array();
51 $this->mCategoryLinks
= array() ;
52 $this->mDoNothing
= false;
53 $this->mContainsOldMagic
= $this->mContainsNewMagic
= 0;
54 $this->mParserOptions
= ParserOptions
::newFromUser( $temp = NULL );
55 $this->mSquidMaxage
= 0;
58 $this->mRevisionId
= null;
61 function addHeader( $name, $val ) { array_push( $this->mHeaders
, $name.': '.$val ) ; }
62 function addCookie( $name, $val ) { array_push( $this->mCookies
, array( $name, $val ) ); }
63 function redirect( $url, $responsecode = '302' ) { $this->mRedirect
= $url; $this->mRedirectCode
= $responsecode; }
64 function setStatusCode( $statusCode ) { $this->mStatusCode
= $statusCode; }
66 # To add an http-equiv meta tag, precede the name with "http:"
67 function addMeta( $name, $val ) { array_push( $this->mMetatags
, array( $name, $val ) ); }
68 function addKeyword( $text ) { array_push( $this->mKeywords
, $text ); }
69 function addScript( $script ) { $this->mScripts
.= $script; }
70 function getScript() { return $this->mScripts
; }
72 function setETag($tag) { $this->mETag
= $tag; }
73 function setArticleBodyOnly($only) { $this->mArticleBodyOnly
= $only; }
74 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly
; }
76 function addLink( $linkarr ) {
77 # $linkarr should be an associative array of attributes. We'll escape on output.
78 array_push( $this->mLinktags
, $linkarr );
81 function addMetadataLink( $linkarr ) {
82 # note: buggy CC software only reads first "meta" link
83 static $haveMeta = false;
84 $linkarr['rel'] = ($haveMeta) ?
'alternate meta' : 'meta';
85 $this->addLink( $linkarr );
90 * checkLastModified tells the client to use the client-cached page if
91 * possible. If sucessful, the OutputPage is disabled so that
92 * any future call to OutputPage->output() have no effect. The method
93 * returns true iff cache-ok headers was sent.
95 function checkLastModified ( $timestamp ) {
96 global $wgCachePages, $wgUser;
97 if ( !$timestamp ||
$timestamp == '19700101000000' ) {
98 wfDebug( "CACHE DISABLED, NO TIMESTAMP\n" );
101 if( !$wgCachePages ) {
102 wfDebug( "CACHE DISABLED\n", false );
105 if( $wgUser->getOption( 'nocache' ) ) {
106 wfDebug( "USER DISABLED CACHE\n", false );
110 $timestamp=wfTimestamp(TS_MW
,$timestamp);
111 $lastmod = wfTimestamp( TS_RFC2822
, max( $timestamp, $wgUser->mTouched
) );
113 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
114 # IE sends sizes after the date like this:
115 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
116 # this breaks strtotime().
117 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
118 $modsinceTime = strtotime( $modsince );
119 $ismodsince = wfTimestamp( TS_MW
, $modsinceTime ?
$modsinceTime : 1 );
120 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
121 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
122 if( ($ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) ) {
123 # Make sure you're in a place you can leave when you call us!
124 header( "HTTP/1.0 304 Not Modified" );
125 $this->mLastModified
= $lastmod;
126 $this->sendCacheControl();
127 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
129 @ob_end_clean
(); // Don't output compressed blob
132 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
133 $this->mLastModified
= $lastmod;
136 wfDebug( "client did not send If-Modified-Since header\n", false );
137 $this->mLastModified
= $lastmod;
141 function getPageTitleActionText () {
150 // Display title is already customized
153 return wfMsg('history_short');
155 // FIXME: bug 2735; not correct for special pages etc
156 return wfMsg('preview');
158 return wfMsg('info_short');
164 function setRobotpolicy( $str ) { $this->mRobotpolicy
= $str; }
165 function setHTMLTitle( $name ) {$this->mHTMLtitle
= $name; }
166 function setPageTitle( $name ) {
167 global $action, $wgContLang;
168 $name = $wgContLang->convert($name, true);
169 $this->mPagetitle
= $name;
170 if(!empty($action)) {
171 $taction = $this->getPageTitleActionText();
172 if( !empty( $taction ) ) {
173 $name .= ' - '.$taction;
177 $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
179 function getHTMLTitle() { return $this->mHTMLtitle
; }
180 function getPageTitle() { return $this->mPagetitle
; }
181 function setSubtitle( $str ) { $this->mSubtitle
= /*$this->parse(*/$str/*)*/; } // @bug 2514
182 function getSubtitle() { return $this->mSubtitle
; }
183 function isArticle() { return $this->mIsarticle
; }
184 function setPrintable() { $this->mPrintable
= true; }
185 function isPrintable() { return $this->mPrintable
; }
186 function setSyndicated( $show = true ) { $this->mShowFeedLinks
= $show; }
187 function isSyndicated() { return $this->mShowFeedLinks
; }
188 function setOnloadHandler( $js ) { $this->mOnloadHandler
= $js; }
189 function getOnloadHandler() { return $this->mOnloadHandler
; }
190 function disable() { $this->mDoNothing
= true; }
192 function setArticleRelated( $v ) {
193 $this->mIsArticleRelated
= $v;
195 $this->mIsarticle
= false;
198 function setArticleFlag( $v ) {
199 $this->mIsarticle
= $v;
201 $this->mIsArticleRelated
= $v;
205 function isArticleRelated() { return $this->mIsArticleRelated
; }
207 function getLanguageLinks() { return $this->mLanguageLinks
; }
208 function addLanguageLinks($newLinkArray) {
209 $this->mLanguageLinks +
= $newLinkArray;
211 function setLanguageLinks($newLinkArray) {
212 $this->mLanguageLinks
= $newLinkArray;
215 function getCategoryLinks() {
216 return $this->mCategoryLinks
;
218 function addCategoryLinks($newLinkArray) {
219 $this->mCategoryLinks +
= $newLinkArray;
221 function setCategoryLinks($newLinkArray) {
222 $this->mCategoryLinks +
= $newLinkArray;
225 function suppressQuickbar() { $this->mSuppressQuickbar
= true; }
226 function isQuickbarSuppressed() { return $this->mSuppressQuickbar
; }
228 function addHTML( $text ) { $this->mBodytext
.= $text; }
229 function clearHTML() { $this->mBodytext
= ''; }
230 function getHTML() { return $this->mBodytext
; }
231 function debug( $text ) { $this->mDebugtext
.= $text; }
234 function setParserOptions( $options ) {
235 return $this->ParserOptions( $options );
238 function ParserOptions( $options = null ) {
239 return wfSetVar( $this->mParserOptions
, $options );
243 * Set the revision ID which will be seen by the wiki text parser
244 * for things such as embedded {{REVISIONID}} variable use.
245 * @param mixed $revid an integer, or NULL
246 * @return mixed previous value
248 function setRevisionId( $revid ) {
249 $val = is_null( $revid ) ?
null : intval( $revid );
250 return wfSetVar( $this->mRevisionId
, $val );
254 * Convert wikitext to HTML and add it to the buffer
255 * Default assumes that the current page title will
258 function addWikiText( $text, $linestart = true ) {
260 $this->addWikiTextTitle($text, $wgTitle, $linestart);
263 function addWikiTextWithTitle($text, &$title, $linestart = true) {
264 $this->addWikiTextTitle($text, $title, $linestart);
267 function addWikiTextTitle($text, &$title, $linestart) {
269 $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions
,
270 $linestart, true, $this->mRevisionId
);
271 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
272 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
273 if ( $parserOutput->getCacheTime() == -1 ) {
274 $this->enableClientCache( false );
276 $this->addHTML( $parserOutput->getText() );
280 * Add wikitext to the buffer, assuming that this is the primary text for a page view
281 * Saves the text into the parser cache if possible
283 function addPrimaryWikiText( $text, $cacheArticle ) {
284 global $wgParser, $wgParserCache, $wgUser;
286 $parserOutput = $wgParser->parse( $text, $cacheArticle->mTitle
,
287 $this->mParserOptions
, true, true, $this->mRevisionId
);
289 $text = $parserOutput->getText();
291 if ( $cacheArticle && $parserOutput->getCacheTime() != -1 ) {
292 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
295 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
296 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
297 if ( $parserOutput->getCacheTime() == -1 ) {
298 $this->enableClientCache( false );
300 $this->addHTML( $text );
304 * Add the output of a QuickTemplate to the output buffer
305 * @param QuickTemplate $template
307 function addTemplate( &$template ) {
309 $template->execute();
310 $this->addHtml( ob_get_contents() );
315 * Parse wikitext and return the HTML. This is for special pages that add the text later
317 function parse( $text, $linestart = true ) {
318 global $wgParser, $wgTitle;
319 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions
,
320 $linestart, true, $this->mRevisionId
);
321 return $parserOutput->getText();
330 function tryParserCache( $article, $user ) {
331 global $wgParserCache;
332 $parserOutput = $wgParserCache->get( $article, $user );
333 if ( $parserOutput !== false ) {
334 $this->mLanguageLinks +
= $parserOutput->getLanguageLinks();
335 $this->mCategoryLinks +
= $parserOutput->getCategoryLinks();
336 $this->addHTML( $parserOutput->getText() );
337 $t = $parserOutput->getTitleText();
339 $this->setPageTitle( $t );
348 * Set the maximum cache time on the Squid in seconds
351 function setSquidMaxage( $maxage ) {
352 $this->mSquidMaxage
= $maxage;
356 * Use enableClientCache(false) to force it to send nocache headers
359 function enableClientCache( $state ) {
360 return wfSetVar( $this->mEnableClientCache
, $state );
363 function uncacheableBecauseRequestvars() {
365 return $wgRequest->getText('useskin', false) === false
366 && $wgRequest->getText('uselang', false) === false;
369 function sendCacheControl() {
370 global $wgUseSquid, $wgUseESI;
373 header("ETag: $this->mETag");
375 # don't serve compressed data to clients who can't handle it
376 # maintain different caches for logged-in users and non-logged in ones
377 header( 'Vary: Accept-Encoding, Cookie' );
378 if( !$this->uncacheableBecauseRequestvars() && $this->mEnableClientCache
) {
379 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
380 ! $this->isPrintable() && $this->mSquidMaxage
!= 0 )
383 # We'll purge the proxy cache explicitly, but require end user agents
384 # to revalidate against the proxy on each visit.
385 # Surrogate-Control controls our Squid, Cache-Control downstream caches
386 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
387 # start with a shorter timeout for initial testing
388 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
389 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage
.', content="ESI/1.0"');
390 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
392 # We'll purge the proxy cache for anons explicitly, but require end user agents
393 # to revalidate against the proxy on each visit.
394 # IMPORTANT! The Squid needs to replace the Cache-Control header with
395 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
396 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
397 # start with a shorter timeout for initial testing
398 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
399 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage
.', must-revalidate, max-age=0' );
402 # We do want clients to cache if they can, but they *must* check for updates
403 # on revisiting the page.
404 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
405 header( "Expires: -1" );
406 header( "Cache-Control: private, must-revalidate, max-age=0" );
408 if($this->mLastModified
) header( "Last-modified: {$this->mLastModified}" );
410 wfDebug( "** no caching **\n", false );
412 # In general, the absence of a last modified header should be enough to prevent
413 # the client from using its cache. We send a few other things just to make sure.
414 header( 'Expires: -1' );
415 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
416 header( 'Pragma: no-cache' );
421 * Finally, all the text has been munged and accumulated into
422 * the object, let's actually output it:
425 global $wgUser, $wgCookieExpiration, $wgOutputEncoding;
426 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType, $wgProfiler;
428 if( $this->mDoNothing
){
431 $fname = 'OutputPage::output';
432 wfProfileIn( $fname );
433 $sk = $wgUser->getSkin();
435 if ( '' != $this->mRedirect
) {
436 if( substr( $this->mRedirect
, 0, 4 ) != 'http' ) {
437 # Standards require redirect URLs to be absolute
439 $this->mRedirect
= $wgServer . $this->mRedirect
;
441 if( $this->mRedirectCode
== '301') {
442 if( !$wgDebugRedirects ) {
443 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
445 $this->mLastModified
= wfTimestamp( TS_RFC2822
);
448 $this->sendCacheControl();
450 if( $wgDebugRedirects ) {
451 $url = htmlspecialchars( $this->mRedirect
);
452 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
453 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
454 print "</body>\n</html>\n";
456 header( 'Location: '.$this->mRedirect
);
458 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
459 wfProfileOut( $fname );
462 elseif ( $this->mStatusCode
)
464 $statusMessage = array(
466 101 => 'Switching Protocols',
471 203 => 'Non-Authoritative Information',
473 205 => 'Reset Content',
474 206 => 'Partial Content',
475 207 => 'Multi-Status',
476 300 => 'Multiple Choices',
477 301 => 'Moved Permanently',
480 304 => 'Not Modified',
482 307 => 'Temporary Redirect',
483 400 => 'Bad Request',
484 401 => 'Unauthorized',
485 402 => 'Payment Required',
488 405 => 'Method Not Allowed',
489 406 => 'Not Acceptable',
490 407 => 'Proxy Authentication Required',
491 408 => 'Request Timeout',
494 411 => 'Length Required',
495 412 => 'Precondition Failed',
496 413 => 'Request Entity Too Large',
497 414 => 'Request-URI Too Large',
498 415 => 'Unsupported Media Type',
499 416 => 'Request Range Not Satisfiable',
500 417 => 'Expectation Failed',
501 422 => 'Unprocessable Entity',
503 424 => 'Failed Dependency',
504 500 => 'Internal Server Error',
505 501 => 'Not Implemented',
506 502 => 'Bad Gateway',
507 503 => 'Service Unavailable',
508 504 => 'Gateway Timeout',
509 505 => 'HTTP Version Not Supported',
510 507 => 'Insufficient Storage'
513 if ( $statusMessage[$this->mStatusCode
] )
514 header( 'HTTP/1.1 ' . $this->mStatusCode
. ' ' . $statusMessage[$this->mStatusCode
] );
517 # Buffer output; final headers may depend on later processing
520 # Disable temporary placeholders, so that the skin produces HTML
521 $sk->postParseLinkColour( false );
523 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
524 header( 'Content-language: '.$wgContLanguageCode );
526 $exp = time() +
$wgCookieExpiration;
527 foreach( $this->mCookies
as $name => $val ) {
528 setcookie( $name, $val, $exp, '/' );
531 if ($this->mArticleBodyOnly
) {
532 $this->out($this->mBodytext
);
534 wfProfileIn( 'Output-skin' );
535 $sk->outputPage( $this );
536 wfProfileOut( 'Output-skin' );
539 $this->sendCacheControl();
541 wfProfileOut( $fname );
544 function out( $ins ) {
545 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
546 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
549 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
550 if ( false === $outs ) { $outs = $ins; }
555 function setEncodings() {
556 global $wgInputEncoding, $wgOutputEncoding;
557 global $wgUser, $wgContLang;
559 $wgInputEncoding = strtolower( $wgInputEncoding );
561 if( $wgUser->getOption( 'altencoding' ) ) {
562 $wgContLang->setAltEncoding();
566 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
567 $wgOutputEncoding = strtolower( $wgOutputEncoding );
570 $wgOutputEncoding = $wgInputEncoding;
574 * Returns a HTML comment with the elapsed time since request.
575 * This method has no side effects.
576 * Use wfReportTime() instead.
580 function reportTime() {
581 $time = wfReportTime();
586 * Note: these arguments are keys into wfMsg(), not text!
588 function errorpage( $title, $msg ) {
591 $this->mDebugtext
.= 'Original title: ' .
592 $wgTitle->getPrefixedText() . "\n";
593 $this->setPageTitle( wfMsg( $title ) );
594 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
595 $this->setRobotpolicy( 'noindex,nofollow' );
596 $this->setArticleRelated( false );
597 $this->enableClientCache( false );
598 $this->mRedirect
= '';
600 $this->mBodytext
= '';
601 $this->addWikiText( wfMsg( $msg ) );
602 $this->returnToMain( false );
609 * Display an error page indicating that a given version of MediaWiki is
612 * @param mixed $version The version of MediaWiki needed to use the page
614 function versionRequired( $version ) {
617 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
618 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
619 $this->setRobotpolicy( 'noindex,nofollow' );
620 $this->setArticleRelated( false );
621 $this->mBodytext
= '';
623 $this->addWikiText( wfMsg( 'versionrequiredtext', $version ) );
624 $this->returnToMain();
628 * Display an error page noting that a given permission bit is required.
629 * This should generally replace the sysopRequired, developerRequired etc.
630 * @param string $permission key required
632 function permissionRequired( $permission ) {
635 $this->setPageTitle( wfMsg( 'badaccess' ) );
636 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
637 $this->setRobotpolicy( 'noindex,nofollow' );
638 $this->setArticleRelated( false );
639 $this->mBodytext
= '';
641 $sk = $wgUser->getSkin();
642 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ) );
643 $this->addHTML( wfMsgHtml( 'badaccesstext', $ap, $permission ) );
644 $this->returnToMain();
650 function sysopRequired() {
653 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
654 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
655 $this->setRobotpolicy( 'noindex,nofollow' );
656 $this->setArticleRelated( false );
657 $this->mBodytext
= '';
659 $sk = $wgUser->getSkin();
660 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
661 $this->addHTML( wfMsgHtml( 'sysoptext', $ap ) );
662 $this->returnToMain();
668 function developerRequired() {
671 $this->setPageTitle( wfMsg( 'developertitle' ) );
672 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
673 $this->setRobotpolicy( 'noindex,nofollow' );
674 $this->setArticleRelated( false );
675 $this->mBodytext
= '';
677 $sk = $wgUser->getSkin();
678 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
679 $this->addHTML( wfMsgHtml( 'developertext', $ap ) );
680 $this->returnToMain();
683 function loginToUse() {
684 global $wgUser, $wgTitle, $wgContLang;
686 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
687 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
688 $this->setRobotpolicy( 'noindex,nofollow' );
689 $this->setArticleFlag( false );
690 $this->mBodytext
= '';
691 $loginpage = Title
::makeTitle(NS_SPECIAL
, 'Userlogin');
692 $sk = $wgUser->getSkin();
693 $loginlink = $sk->makeKnownLinkObj($loginpage, wfMsg('loginreqlink'),
694 'returnto=' . htmlspecialchars($wgTitle->getPrefixedDBkey()));
695 $this->addHTML( wfMsgHtml( 'loginreqpagetext', $loginlink ) );
697 # We put a comment in the .html file so a Sysop can diagnose the page the
699 $this->addHTML( "\n<!--" .
700 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
702 $wgTitle->getDBkey() . '-->' );
703 $this->returnToMain(); # Flip back to the main page after 10 seconds.
706 function databaseError( $fname, $sql, $error, $errno ) {
707 global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
709 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
710 $this->setRobotpolicy( 'noindex,nofollow' );
711 $this->setArticleRelated( false );
712 $this->enableClientCache( false );
713 $this->mRedirect
= '';
715 if( !$wgShowSQLErrors ) {
716 $sql = wfMsg( 'sqlhidden' );
719 if ( $wgCommandLineMode ) {
720 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
721 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
723 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
724 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
727 if ( $wgCommandLineMode ||
!is_object( $wgUser )) {
731 $this->mBodytext
= $msg;
736 function readOnlyPage( $source = null, $protected = false ) {
737 global $wgUser, $wgReadOnlyFile, $wgReadOnly;
739 $this->setRobotpolicy( 'noindex,nofollow' );
740 $this->setArticleRelated( false );
743 $this->setPageTitle( wfMsg( 'viewsource' ) );
744 $this->addWikiText( wfMsg( 'protectedtext' ) );
746 $this->setPageTitle( wfMsg( 'readonly' ) );
748 $reason = $wgReadOnly;
750 $reason = file_get_contents( $wgReadOnlyFile );
752 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
755 if( is_string( $source ) ) {
756 if( strcmp( $source, '' ) == 0 ) {
757 $source = wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' );
759 $rows = $wgUser->getOption( 'rows' );
760 $cols = $wgUser->getOption( 'cols' );
761 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
762 htmlspecialchars( $source ) . "\n</textarea>";
763 $this->addHTML( $text );
766 $this->returnToMain( false );
769 function fatalError( $message ) {
770 $this->setPageTitle( wfMsg( "internalerror" ) );
771 $this->setRobotpolicy( "noindex,nofollow" );
772 $this->setArticleRelated( false );
773 $this->enableClientCache( false );
774 $this->mRedirect
= '';
776 $this->mBodytext
= $message;
781 function unexpectedValueError( $name, $val ) {
782 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
785 function fileCopyError( $old, $new ) {
786 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
789 function fileRenameError( $old, $new ) {
790 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
793 function fileDeleteError( $name ) {
794 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
797 function fileNotFoundError( $name ) {
798 $this->fatalError( wfMsg( 'filenotfound', $name ) );
802 * return from error messages or notes
803 * @param $auto automatically redirect the user after 10 seconds
804 * @param $returnto page title to return to. Default is Main Page.
806 function returnToMain( $auto = true, $returnto = NULL ) {
807 global $wgUser, $wgOut, $wgRequest;
809 if ( $returnto == NULL ) {
810 $returnto = $wgRequest->getText( 'returnto' );
812 $returnto = htmlspecialchars( $returnto );
814 $sk = $wgUser->getSkin();
815 if ( '' == $returnto ) {
816 $returnto = wfMsgForContent( 'mainpage' );
818 $link = $sk->makeKnownLink( $returnto, '' );
820 $r = wfMsg( 'returnto', $link );
822 $titleObj = Title
::newFromText( $returnto );
823 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
825 $wgOut->addHTML( "\n<p>$r</p>\n" );
829 * This function takes the title (first item of mGoodLinks), categories, existing and broken links for the page
830 * and uses the first 10 of them for META keywords
832 function addMetaTags () {
833 global $wgLinkCache , $wgOut ;
834 $categories = array_keys ( $wgLinkCache->mCategoryLinks
) ;
835 $good = array_keys ( $wgLinkCache->mGoodLinks
) ;
836 $bad = array_keys ( $wgLinkCache->mBadLinks
) ;
837 $a = array_merge ( array_slice ( $good , 0 , 1 ), $categories, array_slice ( $good , 1 , 9 ) , $bad ) ;
838 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
839 $a = implode ( ',' , $a ) ;
844 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
846 $wgOut->addMeta( 'keywords' , $a ) ;
853 function headElement() {
854 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
855 global $wgUser, $wgContLang, $wgRequest, $wgUseTrackbacks, $wgTitle;
857 if( $wgMimeType == 'text/xml' ||
$wgMimeType == 'application/xhtml+xml' ||
$wgMimeType == 'application/xml' ) {
858 $ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
863 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
865 if ( '' == $this->getHTMLTitle() ) {
866 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
869 $rtl = $wgContLang->isRTL() ?
" dir='RTL'" : '';
870 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
871 $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
872 array_push( $this->mMetatags
, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
874 $ret .= $this->getHeadLinks();
876 if( $this->isPrintable() ) {
879 $media = "media='print'";
881 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
882 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
884 $sk = $wgUser->getSkin();
885 $ret .= $sk->getHeadScripts();
886 $ret .= $this->mScripts
;
887 $ret .= $sk->getUserStyles();
889 if ($wgUseTrackbacks && $this->isArticleRelated())
890 $ret .= $wgTitle->trackbackRDF();
896 function getHeadLinks() {
897 global $wgRequest, $wgStylePath;
899 foreach ( $this->mMetatags
as $tag ) {
900 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
902 $tag[0] = substr( $tag[0], 5 );
906 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
909 $p = $this->mRobotpolicy
;
910 if( $p !== '' && $p != 'index,follow' ) {
911 // http://www.robotstxt.org/wc/meta-user.html
912 // Only show if it's different from the default robots policy
913 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
916 if ( count( $this->mKeywords
) > 0 ) {
921 $ret .= "<meta name=\"keywords\" content=\"" .
922 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords
))) . "\" />\n";
924 foreach ( $this->mLinktags
as $tag ) {
926 foreach( $tag as $attr => $val ) {
927 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
931 if( $this->isSyndicated() ) {
932 # FIXME: centralize the mime-type and name information in Feed.php
933 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
934 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
935 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
936 $ret .= "<link rel='alternate' type='application/atom+xml' title='Atom 0.3' href='$link' />\n";
943 * Turn off regular page output and return an error reponse
944 * for when rate limiting has triggered.
948 function rateLimited() {
951 wfHttpError( 500, 'Internal Server Error',
952 'Sorry, the server has encountered an internal error. ' .
953 'Please wait a moment and hit "refresh" to submit the request again.' );